/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.insaneSolver;

import br.ufmg.dees.insane.model.femModel.FemModel;
import br.ufmg.dees.insane.model.postp.PostpModel;
import br.ufmg.dees.insane.model.postp.StepPostp;
import br.ufmg.dees.insane.parser.FemModelToPostpModel;
import br.ufmg.dees.insane.persistence.PersistenceAsInsane;
import br.ufmg.dees.insane.persistence.PersistenceAsXML;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.InterfacePostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.PostpViewState;

/**
 * @author Penna, S. S., Pitangueira, Roque
 * @since 14/12/2006
 */
public class ShowMeshValue implements Runnable{
	private FemModelToPostpModel parser;
	private StepPostp postpStep;
	private DesktopPostp parent;
	private PersistenceAsXML p;
	private SynchronizedSettings synchSettings;
	private String modelLabel;
	
	public ShowMeshValue(DesktopPostp parent, PersistenceAsXML p,PersistenceAsInsane o){
		this.parent = parent;
		this.p = p;
	}
	
	public void run() {
		
		try{
			Thread.sleep(100);
			parser = new FemModelToPostpModel((FemModel)p.getModel());
			parser.setSolution(p.getSolution());
			(p.getModel()).addObserver(parser);
			postpStep = parser.getStepPostp(); 
			postpStep.setLabel("Model");
			InterfacePostp intFrame = new InterfacePostp();
			intFrame.setTitle("Model");
			intFrame.validate();
			
			if(synchSettings.isNodalValuesOnOff()){
				((PostpViewState)intFrame.getView().getViewState()).getNodalsPlotContoursViewState().setContourMeshStateOnOff(true);
				((PostpViewState)intFrame.getView().getViewState()).getNodalsPlotContoursViewState().setKeyValue(synchSettings.getValueKey());
			}
			if(synchSettings.isElementsValuesOnOff()){
				((PostpViewState)intFrame.getView().getViewState()).getElementsPlotContoursViewState().setContourMeshStateOnOff(true);
				((PostpViewState)intFrame.getView().getViewState()).getElementsPlotContoursViewState().setKeyValue(synchSettings.getValueKey());
			}
			if(synchSettings.isViewOnMeshStateOnOff()){
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setMeshOnOff(false);
				((PostpViewState)intFrame.getView().getViewState()).getVertexViewState().setVertexOnOff(false);
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setMeshStateOnOff(true);
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setXKey(synchSettings.getMeshStateKeyX());
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setYKey(synchSettings.getMeshStateKeyY());
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setZKey(synchSettings.getMeshStateKeyZ());
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setXScale(synchSettings.getScaleX());
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setYScale(synchSettings.getScaleY());
				((PostpViewState)intFrame.getView().getViewState()).getMeshStateViewState().setZScale(synchSettings.getScaleZ());
				
			}
			
			postpStep = parser.getStepPostp();
			intFrame.setModel(postpStep);
			PostpModel postpModel = new PostpModel();
			postpModel.addStep(postpStep);
			intFrame.setPostpModel(postpModel);
			(this.parent).addInternalFrame(intFrame);
			intFrame.toFront();	
			
			this.parent.setInterface();
			parser.addObserver(intFrame);
			
		}catch (Exception e){
			System.out.println("Thread error Mesh Value");
		}
	}
	
	public SynchronizedSettings getSynchSettings() {
		return synchSettings;
	}
	
	public void setSynchSettings(SynchronizedSettings synchSettings) {
		this.synchSettings = synchSettings;
	}
	
	public String getModelLabel() {
		return modelLabel;
	}
	
	public void setModelLabel(String modelLabel) {
		this.modelLabel = modelLabel;
	}
	
//	*****************************************************************************************************************************	
}//end of this class
